import scrapy


class myscrapy(scrapy.Spider):
    name = "mys"

    start_urls = [  #另外一种写法，无需定义start_requests方法
        'http://lab.scrapyd.cn/page/1/',
        'http://lab.scrapyd.cn/page/2/',
    ]

    def parse(self, response):
        # page = response.url.split("/")[-2]
        # filename = 'mingyan-%s.html' % page
        # with open(filename, 'wb') as f:
        #     f.write(response.body)
        # self.log('保存文件: %s' % filename)

        p = response.css('div.quote')[0]
        text = p.css('.text::text').extract_first()
        autor = p.css('.author::text').extract_first()

        fileName = '%s-aa.txt' % autor
        f = open(fileName, "a+")
        f.write(text)
        f.close
